home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / TGE133.ZIP;1 / INCLUDE / VARFONT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  6.2 KB  |  201 lines

  1. /*****************************************************************************
  2. *       The Graphics Engine version 1.33                                     *
  3. *                                                                            *
  4. *       The Graphics Engine code and documentation are                       *
  5. *       Copyright (c) 1993-1994 by Matthew Hildebrand; all rights reserved.  *
  6. *                                                                            *
  7. *       Unauthorised usage or modification of any or all of The Graphics     *
  8. *       Engine is strictly prohibited.                                       *
  9. *****************************************************************************/
  10.  
  11. #if !defined(VARFONTdotH)
  12. #define VARFONTdotH
  13.  
  14.  
  15.  
  16. //*****
  17. //***** Structure used by the VariableFont class.
  18. //*****
  19.  
  20. #pragma option -a-
  21.  
  22. struct FontCharInfo
  23. {
  24.   unsigned short offsetFromTop;
  25.   unsigned short wide, deep;
  26.   void far *bitmap;
  27. };
  28.  
  29. #pragma option -a
  30.  
  31.  
  32.  
  33. //*****
  34. //***** Class for dealing with variable-sized, 256-colour, loadable fonts.
  35. //*****
  36.  
  37. class VariableFont
  38. {
  39.   unsigned char fontPalette[768], colourTranslate[256];
  40.   FontCharInfo characters[256];
  41.   void far *characterData, *charBuf;
  42.   unsigned short maxWide, maxHigh;
  43.   unsigned spaceBetweenChars;
  44. public:
  45.   VariableFont(void);
  46.   ~VariableFont(void);
  47.   int load(char *filename);                     // returns 0 on error
  48.   int load(unsigned char *filename)              { return load((char*)filename); }
  49.   void put(int x, int y, char ch);
  50.   void put(int x, int y, char *string);
  51.   void put(int x, int y, unsigned char *string)  { put(x,y,(char*)string); }
  52.   void put(int x, int y, unsigned char ch)       { put(x,y,(char)ch);      }
  53.   unsigned width(char *string);
  54.   unsigned width(unsigned char *string)          { return width((char*)string);  }
  55.   unsigned height(char *string);
  56.   unsigned height(unsigned char *string)         { return height((char*)string); }
  57.   inline unsigned short width(char ch);
  58.   unsigned short width(unsigned char ch)         { return width((char)ch);       }
  59.   inline unsigned short height(char ch);
  60.   unsigned short height(unsigned char ch)        { return height((char)ch);      }
  61.   inline unsigned short maxWidth(void);
  62.   inline unsigned short maxHeight(void);
  63.   void matchColours(void);
  64.   void palette(void *palette);
  65.   void palette(unsigned char palReg, unsigned char red, unsigned char green,
  66.                unsigned char blue);
  67.   void palette(unsigned char palReg, unsigned char *red, unsigned char *green,
  68.                unsigned char *blue);
  69.   inline void *palette(void);
  70.   inline void spacing(unsigned numPixels);
  71.   inline unsigned spacing(void);
  72. };
  73.  
  74.  
  75.  
  76. /**************************************************************************
  77. *  Function:    VariableFont::width
  78. *
  79. *  Purpose:     Return the width, in pixels, of a single character.
  80. *
  81. *  Entry:       ch = Character of which to find the width.
  82. *
  83. *  Exit:        Returns the width of the character in pixels, not
  84. *               accounting for blank space on either side.
  85. **************************************************************************/
  86.  
  87. inline unsigned short VariableFont::width(char ch)
  88. {
  89.   return (characters[(unsigned)ch].wide);
  90. }
  91.  
  92.  
  93.  
  94. /**************************************************************************
  95. *  Function:    VariableFont::height
  96. *
  97. *  Purpose:     Return the height, in pixels, of a single character's
  98. *               bitmap.  The offsetFromTop value is ignored.
  99. *
  100. *  Entry:       ch = Character of which to find the height.
  101. *
  102. *  Exit:        Returns the height of the character in pixels, not
  103. *               accounting for blank space above or below.
  104. **************************************************************************/
  105.  
  106. inline unsigned short VariableFont::height(char ch)
  107. {
  108.   return (characters[(unsigned)ch].deep);
  109. }
  110.  
  111.  
  112.  
  113. /**************************************************************************
  114. *  Function:    VariableFont::maxWidth
  115. *
  116. *  Purpose:     Return the width, in pixels, of the widest character.
  117. *
  118. *  Entry:       N/A
  119. *
  120. *  Exit:        Returns the width of the widest character in pixels, not
  121. *               accounting for blank space used between characters.
  122. **************************************************************************/
  123.  
  124. inline unsigned short VariableFont::maxWidth(void)
  125. {
  126.   return (maxWide);
  127. }
  128.  
  129.  
  130.  
  131. /**************************************************************************
  132. *  Function:    VariableFont::maxHeight
  133. *
  134. *  Purpose:     Return the height, in pixels, of the tallest character.
  135. *
  136. *  Entry:       N/A
  137. *
  138. *  Exit:        Returns the height of the tallest character in pixels, not
  139. *               accounting for blank space above or below.
  140. **************************************************************************/
  141.  
  142. inline unsigned short VariableFont::maxHeight(void)
  143. {
  144.   return (maxHigh);
  145. }
  146.  
  147.  
  148.  
  149. /**************************************************************************
  150. *  Function:    VariableFont::palette
  151. *
  152. *  Purpose:     Return the current font palette.
  153. *
  154. *  Entry:       N/A
  155. *
  156. *  Exit:        Returns the address of the current font palette.
  157. **************************************************************************/
  158.  
  159. inline void *VariableFont::palette(void)
  160. {
  161.   return (fontPalette);
  162. }
  163.  
  164.  
  165.  
  166. /**************************************************************************
  167. *  Function:    VariableFont::spacing
  168. *
  169. *  Purpose:     Set the spacing, in pixels, between characters.
  170. *
  171. *  Entry:       numPixels = New spacing value, in pixels.
  172. *
  173. *  Exit:        N/A
  174. **************************************************************************/
  175.  
  176. inline void VariableFont::spacing(unsigned numPixels)
  177. {
  178.   spaceBetweenChars = numPixels;            // change spacing value
  179. }
  180.  
  181.  
  182.  
  183. /**************************************************************************
  184. *  Function:    VariableFont::spacing
  185. *
  186. *  Purpose:     Return the spacing, in pixels, between characters.
  187. *
  188. *  Entry:       N/A
  189. *
  190. *  Exit:        Returns the spacing in pixels.
  191. **************************************************************************/
  192.  
  193. inline unsigned VariableFont::spacing(void)
  194. {
  195.   return (spaceBetweenChars);               // return spacing value
  196. }
  197.  
  198.  
  199.  
  200. #endif
  201.